package com.gzy.xuexiziliao.controller;

import com.gzy.xuexiziliao.common.result.Result;
import com.gzy.xuexiziliao.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 文件上传
 */
@RestController
@Slf4j
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;
    @PostMapping("/upload")
    public Result upload(MultipartFile image) throws IOException {
        log.info("上传图片,文件名：{}", image.getOriginalFilename());
        String url = aliOSSUtils.upload(image);
        log.info("上传图片成功，图片路径：{}", url);
        return Result.success(url);
    }
}
